package com.haoshuang.zhouzhoubang.ui.vm

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class SetEmergencyContactViewModel : BaseViewModel() {

    /**
     * 发送短信验证码
     */
    val sendSmsData = StatefulMutableLiveData<Any>()
    fun sendSms(mobile: String) = netRequest {
        start { sendSmsData.value = StateData.Loading }
        request { ApiRepo.senSms(mobile, 13) }
        success { sendSmsData.value = StateData.Success(it.data) }
        error { code, msg ->
            sendSmsData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 修改紧急电话
     */
    val editEmergencyContactData = StatefulMutableLiveData<Any>()
    fun editEmergencyContact(mobile: String, code: String) = netRequest {
        start { editEmergencyContactData.value = StateData.Loading }
        request { ApiRepo.editEmergencyContact(mobile, code) }
        success { editEmergencyContactData.value = StateData.Success(it.data) }
        error { code, msg ->
            editEmergencyContactData.value = StateData.Error(code, msg)
        }
    }
}